# def singleyeardata(request):
#     if request.method=='GET':
#         uid = request.GET.get('nid')
#         rettimelist=[]
#         retdatalist=[]
#         last = models.ElectricDeviceData.objects.filter(ug_id=uid).last()
#         first= models.ElectricDeviceData.objects.filter(ug_id=uid).first()
#         lasttime=time.strftime("%Y%m", time.localtime(first.time))
#         firsttime=time.strftime("%Y%m", time.localtime(last.time))
#         if lasttime==firsttime:
#             lastmonthindex=month.index(lasttime[4:6])
#             firstmonthindex=month.index(lasttime[4:6])
#             for i in month[firstmonthindex:lastmonthindex+1]:
#                 if i=='12':
#                     utcfirst = int(time.mktime(time.strptime((lasttime[0:4] + i), "%Y%m")))
#                     utclast=int(time.mktime(time.strptime(str(int(lasttime[0:4]) + 1), "%Y")))
#                 else:
#                     utcfirst = int(time.mktime(time.strptime((lasttime[0:4]+i), "%Y%m")))
#                     utclast = int(time.mktime(time.strptime((lasttime[0:4]+month[month.index(i)+1]), "%Y%m")))
#                 datafirst=models.ElectricDeviceData.objects.filter(ug_id=uid,time__gte=utcfirst).first()
#                 datalast=models.ElectricDeviceData.objects.filter(ug_id=uid,time__lte=utclast).last()
#                 data=round(datalast.one1-datafirst.one1,4)
#                 retdatalist.append(int(data*100))
#                 rettimelist.append(lasttime[0:4]+i)
#         else:
#             lastmonthindex = month.index(lasttime[4:6])
#             for i in month[0:lastmonthindex + 1]:
#                 if i=='12':
#                     utcfirst = int(time.mktime(time.strptime((lasttime[0:4] + i), "%Y%m")))
#                     utclast=int(time.mktime(time.strptime(str(int(lasttime[0:4]) + 1), "%Y")))
#                 else:
#                     utcfirst = int(time.mktime(time.strptime((lasttime[0:4]+i), "%Y%m")))
#                     utclast = int(time.mktime(time.strptime((lasttime[0:4]+month[month.index(i)+1]), "%Y%m")))
#                 datafirst=models.ElectricDeviceData.objects.filter(ug_id=uid,time__gte=utcfirst).first()
#                 datalast=models.ElectricDeviceData.objects.filter(ug_id=uid,time__lte=utclast).last()
#                 data=datalast.one1-datafirst.one1
#                 retdatalist.append(int(data*100))
#                 rettimelist.append(lasttime[0:4]+i)
#         rsp={
#             "errno": 0,
#             "data": {
#                 "optionsA": {
#                     "xAxis":rettimelist,
#                     "series":
#                         {
#                             "data":retdatalist
#                         }
#                 }}}
#         return JsonResponse(rsp)
#
# def totalyeardata(request):
#     if request.method=='GET':
#         rettimelist = []
#         retdatalist = []
#         last = models.ElectricDeviceData.objects.all().last()
#         first = models.ElectricDeviceData.objects.all().first()
#         firsttime = time.strftime("%Y%m", time.localtime(first.time))
#         lasttime = time.strftime("%Y%m", time.localtime(last.time))
#         if lasttime == firsttime:
#             lastmonthindex = month.index(lasttime[4:6])
#             firstmonthindex = month.index(lasttime[4:6])
#             for i in month[firstmonthindex:lastmonthindex + 1]:
#                 if i == '12':
#                     utcfirst = int(time.mktime(time.strptime((lasttime[0:4] + i), "%Y%m")))
#                     utclast = int(time.mktime(time.strptime(str(int(lasttime[0:4]) + 1), "%Y")))
#                 else:
#                     utcfirst = int(time.mktime(time.strptime((lasttime[0:4] + i), "%Y%m")))
#                     utclast = int(time.mktime(time.strptime((lasttime[0:4] + month[month.index(i) + 1]), "%Y%m")))
#                 sum=0
#                 for j in dataList:
#                     uid = models.ElectricDeviceList.objects.get(deviceMac=j)
#                     datafirst = models.ElectricDeviceData.objects.filter(ug_id=uid.id, time__gte=utcfirst).first()
#                     datalast = models.ElectricDeviceData.objects.filter(ug_id=uid.id, time__lte=utclast).last()
#                     data = datalast.one1 - datafirst.one1
#                     sum=sum+data
#                 retdatalist.append(round(sum * 100,2))
#                 rettimelist.append(lasttime[0:4] + i)
#         else:
#             lastmonthindex = month.index(lasttime[4:6])
#             for i in month[0:lastmonthindex + 1]:
#                 if i == '12':
#                     utcfirst = int(time.mktime(time.strptime((lasttime[0:4] + i), "%Y%m")))
#                     utclast = int(time.mktime(time.strptime(str(int(lasttime[0:4]) + 1), "%Y")))
#                 else:
#                     utcfirst = int(time.mktime(time.strptime((lasttime[0:4] + i), "%Y%m")))
#                     print(lasttime[0:4] + i)
#                     utclast = int(time.mktime(time.strptime((lasttime[0:4] + month[month.index(i) + 1]), "%Y%m")))
#                     print(lasttime[0:4] + month[month.index(i) + 1])
#                 sum=0
#                 for j in dataList:
#                     uid = models.ElectricDeviceList.objects.get(deviceMac=j)
#                     datafirst = models.ElectricDeviceData.objects.filter(ug_id=uid.id, time__gte=utcfirst).first()
#                     datalast = models.ElectricDeviceData.objects.filter(ug_id=uid.id, time__lte=utclast).last()
#                     data = datalast.one1 - datafirst.one1
#                     sum=sum+data
#                 retdatalist.append(round(sum * 100,2))
#                 rettimelist.append(lasttime[0:4] + i)
#         rsp={
#             "errno": 0,
#             "data": {
#                 "optionsA": {
#                     "xAxis":rettimelist,
#                     "series":
#                         {
#                             "data":retdatalist
#                         }
#                 }}}
#         return JsonResponse(rsp)